//
//  ReceiveRuleView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/6/7.
//

#import "ReceiveRuleView.h"
#import "CommonUtil.h"

@interface ReceiveRuleView()

@property (strong, nonatomic) UILabel * label1;
@property (strong, nonatomic) UIButton * ruleBtn;
@property (strong, nonatomic) UIButton * receiveBtn;

@end


@implementation ReceiveRuleView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.layer.cornerRadius = AD(5);
        self.backgroundColor = [UIColor whiteColor];
        self.clipsToBounds = YES;
        [self addSubview:self.label1];
        [self addSubview:self.ruleBtn];
        [self addSubview:self.receiveBtn];
        
        NSArray *titles1 = @[@"+1",@"+1",@"+2",@"+3",@"+4",@"+4",@"+5"];
        NSArray *titles2 = @[@"一天",@"二天",@"三天",@"四天",@"五天",@"六天",@"七天"];
        
        CGFloat margin = AD(5);
        CGFloat wh =(self.width-AD(20+30))/7;
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(AD(10) + (wh/2), 0, self.width-AD(20)-wh, AD(1))];
        lineView.backgroundColor = RGB(248, 226, 229);
        [self addSubview:lineView];
        for (NSInteger i = 0; i < 7; i++) {
            UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(((wh + margin) * i) + AD(10), _ruleBtn.bottom + AD(20), wh, wh)];
            label1.text = titles1[i];
            label1.textColor = RGB(163, 163, 163);
            label1.textAlignment = NSTextAlignmentCenter;
            label1.font = [UIFont systemFontOfSize:AD(14)];
            [self addSubview:label1];
            label1.layer.cornerRadius = wh/2;
            label1.clipsToBounds = YES;
            label1.backgroundColor = RGB(248, 226, 229);
            lineView.centerY = label1.centerY;
            
            
            UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(label1.left, label1.bottom + AD(5), wh, AD(15))];
            label2.text = titles2[i];
            label2.textColor = [UIColor lightGrayColor];
            label2.textAlignment = NSTextAlignmentCenter;
            [self addSubview:label2];
            label2.font = [UIFont systemFontOfSize:AD(14)];
            
        }
        
        
    }
    return self;
}

- (void)ruleBtnClick:(UIButton *)sender{
    NSLog(@"%@",sender.titleLabel.text);
}


- (void)btnClick:(UIButton *)sender{
    NSLog(@"%@",sender.titleLabel.text);
}

-(UILabel *)label1{
    if (!_label1) {
        _label1 = [[UILabel alloc] initWithFrame:CGRectMake(AD(8), AD(8), self.width, AD(20))];
        _label1.text = @"天天领取小红花";
        _label1.textColor = RGB(139, 139, 139);
        _label1.font = [UIFont systemFontOfSize:AD(15)];
    }
    return _label1;
}

-(UIButton *)ruleBtn{
    if (!_ruleBtn) {
        _ruleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_ruleBtn addTarget:self action:@selector(ruleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_ruleBtn setTitle:@"领取规则" forState:UIControlStateNormal];
        [_ruleBtn setTitleColor:RGB(174, 174, 174) forState:UIControlStateNormal];
        _ruleBtn.titleLabel.font = [UIFont systemFontOfSize:AD(13)];
        [_ruleBtn setImage:[UIImage imageNamed:@"icon_rulebtn"] forState:UIControlStateNormal];
        _ruleBtn.frame = CGRectMake(AD(8), _label1.bottom + AD(3), AD(80), AD(20));
        _ruleBtn.imageEdgeInsets = UIEdgeInsetsMake(0, AD(-10), 0, 0);
    }
    return _ruleBtn;
}

-(UIButton *)receiveBtn{
    if (!_receiveBtn) {
        _receiveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_receiveBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_receiveBtn setTitle:@"立即领取" forState:UIControlStateNormal];
        [_receiveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _receiveBtn.titleLabel.font = [UIFont systemFontOfSize:AD(15)];
        _receiveBtn.frame = CGRectMake(AD(8),AD(23), AD(85), AD(30));
        _receiveBtn.layer.cornerRadius = _receiveBtn.height/2;
        _receiveBtn.backgroundColor = RGB(255, 65, 64);
        _receiveBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
        _receiveBtn.right = self.width - AD(10);
    }
    return _receiveBtn;
}


@end
